package main

import (
	"fmt"
	"math/rand"
)

// 九九乘法表
func mulTable() {
	for i := 1; i <= 9; i++ {
		for j := 1; j <= i; j++ {
			fmt.Printf("%d*%d=%2d\t", j, i, i*j)
		}
		fmt.Println()
	}
}

// 随机生成20以内的20个非0正整数，打印出来。
// 对生成的数值，第单数个（不是索引）累加求和，第偶数个累乘求积。打印结果
func randInt() {
	odd := 0
	mul := 1
	for i := 0; i < 20; i++ {
		num := rand.Intn(19) + 1
		if (i+1)%2 == 0 {
			mul *= num
		} else {
			odd += num
		}
		fmt.Println(num)
	}
	fmt.Printf("odd:%d\nmul:%d", odd, mul)
}

// 打印100以内的斐波那契数列
var fiboMap = make(map[int]int, 100)

func fibo(num int) int {
	if i, ok := fiboMap[num]; ok {
		return i
	}
	if num == 1 || num == 2 {
		fiboMap[num] = 1
		return 1
	}
	res := fibo(num-1) + fibo(num-2)
	fiboMap[num] = res
	return res
}

func printFiboMap() {
	_ = fibo(100)
	for i := 1; i <= 100; i++ {
		fmt.Println(fiboMap[i])
	}
}
